// https://leetcode.com/problems/ugly-number-ii/description/

class Solution {
public:
    int nthUglyNumber(int n) {
        vector<int> result = {1};
        int i = 0;
        int j = 0;
        int k = 0;
        for (int m = 1; m < n; m++)
        {
            result.push_back(min(result[i] * 2, min(result[j] * 3, result[k] * 5)));
            if (result.back() == result[i] * 2)
                i++;
            if (result.back() == result[j] * 3) //不能有else，下同
                j++;
            if (result.back() == result[k] * 5)
                k++;
        }
        return result.back();
    }
};
